package com.whut.provider.service.impl;

import com.whut.common.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
@DubboService(version = "1.0")
@Slf4j
public class HelloServiceImpl implements HelloService {

    private final Random costTimeRandom = new Random();

    @Override
    public String sayHello(String name) {
        await();
        return "Hello" + name;
    }

    private void await() {
        try {
            long timeInMillisToWait = costTimeRandom.nextInt(500);
            Thread.sleep(timeInMillisToWait);
            log.info("execution time : " + timeInMillisToWait + " ms.");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
